package org.eureka.consumer;

import org.eureka.consumer.inter.DcClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@RestController
public class DcController {

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    DcClient dcClient;
    
    @GetMapping("/consumer")
    public String dc() {
        return restTemplate.getForObject("http://eureka-client/dc", String.class);
    }

    @GetMapping("/consumer1")
    @HystrixCommand(fallbackMethod = "fallback")
    public String dc1() {
        return  dcClient.consumer()+"consumer1";
    }
    
    public String fallback() {
        return "fallback";
    }
}
